﻿using Coater.Enum;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Coater.UC
{
    public partial class ucFluidSetup : UserControl
    {
        bool Dispensing = false;

        /// <summary>
        /// 喷嘴编号
        /// </summary>
        public NozzleEnum Nozzle
        {
            get => NozzleEnumExtension.GetEnum(this.lbTitle.Text);
            set
            {
                this.lbTitle.Text = value.GetName();
                this.btnDispense.Tag = value.ToString();
            }
        }
        /// <summary>
        /// 喷嘴名称
        /// </summary>
        public string NozzleName
        {
            get => this.txtNozzle.Text;
            set => this.txtNozzle.Text = value;
        }
        public bool Enable
        {
            get => this.chkEnable.Checked;
            set
            {
                this.chkEnable.Checked = value;
                this.numMinutes.Enabled = value;
                this.numSec.Enabled = value;
            }
        }
        /// <summary>
        /// 分钟
        /// </summary>
        public int Minutes
        {
            get => (int)this.numMinutes.Value;
            set => this.numMinutes.Value = value;
        }
        /// <summary>
        /// 秒
        /// </summary>
        public int Sec
        {
            get => (int)this.numSec.Value;
            set => this.numSec.Value = value;
        }


        int CurrPosition { get; set; }

        public ucFluidSetup()
        {
            InitializeComponent();

        }

        private void btnDispense_MouseDown(object sender, MouseEventArgs e)
        {
            Debug.WriteLine("MouseDown");
            if (Dispensing)
            {
                return;
            }
            // TODO: 无目标位置的开始逻辑（点动）
            if (numTargetPosition.Value == 0)
            {
                this.btnDispense.Text = "Dispensing";
                Dispensing = true;
            }
        }

        private void btnDispense_MouseUp(object sender, MouseEventArgs e)
        {
            Debug.WriteLine("MouseUp");
            if (!Dispensing)
            {
                return;
            }
            // TODO: 无目标位置的结束逻辑（点动）
            if (numTargetPosition.Value == 0)
            {
                this.btnDispense.Text = "Dispense";
                Dispensing = false;
            }
        }

        private async void btnDispense_MouseClick(object sender, MouseEventArgs e)
        {
            Debug.WriteLine("MouseClick");
            if (Dispensing)
            {
                return;
            }
            // TODO: 有目标位置的完整逻辑
            if (numTargetPosition.Value > 0)
            {
                this.btnDispense.Text = "Stop";
                Dispensing = true;
                // TODO: 停止
            }
        }

        private void chkEnable_CheckedChanged(object sender, EventArgs e)
        {
            Enable = chkEnable.Checked;
        }

        public void ShowData(NozzleInfo nozzle)
        {
            this.NozzleName = nozzle.NozzleName;
            this.Enable = nozzle.Enable;
            this.Minutes = nozzle.Minutes;
            this.Sec = nozzle.Sec;
        }

        public NozzleInfo GetData()
        {
            return new NozzleInfo()
            {
                Nozzle = this.Nozzle,
                NozzleName = this.NozzleName,
                Enable = this.Enable,
                Minutes = this.Minutes,
                Sec = this.Sec
            };
        }


    }
}
